import { useRequest } from 'ahooks'
import type { Options } from 'ahooks/lib/useRequest/src/types'
import axios from 'axios'

import './__mock__'

/** 业务跟单人员 */
export interface IBusinessUser {
  id: number
  name: string | null
  englishName: string | null
}

interface TRes {
  list: IBusinessUser[]
}

/** SWR 人员 获取业务跟单人员列表 */
export const useBusinessUsers = (opts?: Options<TRes, []>) => {
  return useRequest<TRes, []>(
    async () => {
      const res = await axios.get(`/omsapi/dispatchOrder/businessUsers`)
      const list = res.$data || []
      return { list }
    },
    {
      cacheTime: -1, // 永不过期
      staleTime: 1000 * 60 * 5, // 5 分钟新鲜
      ...opts,
      cacheKey: 'SWRApi_useBusinessUsers',
    },
  )
}
